package com.xxl.job.admin.service.cvt;

import com.xuxueli.api.service.tenantjob.TenantJobInfo;
import com.xxl.job.admin.core.model.XxlJobInfo;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * description:
 * <p>
 * Date: 2019-04-30
 * <p>
 * Time: 13:22
 *
 * @author zhangxin
 */
@Component
public class TenantJobInfoCvtJobInfo {

    public XxlJobInfo cvt(TenantJobInfo source, int jobGroup){
        if(source == null){
            return null;
        }

        XxlJobInfo target =new XxlJobInfo();
        target.setId(0);
        target.setJobGroup(jobGroup);
        target.setJobCron(source.getCron());
        target.setJobDesc(source.getJobName());
        target.setAddTime(new Date());
        target.setUpdateTime(new Date());
        target.setAuthor(source.getAdmin());
        target.setAlarmEmail(source.getWarnEmail());
        target.setExecutorRouteStrategy(source.getExecutorRouteStrategy());
        target.setExecutorHandler(source.getJobHandlerBeanName());
        target.setExecutorParam(source.getParamJson());
        target.setExecutorBlockStrategy(source.getExecutorBlockStrategy());
        target.setExecutorTimeout(Long.valueOf(source.getJobHandlerTimeOut()).intValue());
        target.setExecutorFailRetryCount(Long.valueOf(source.getFailRetryTimes()).intValue());
        target.setGlueType(source.getRunType());

        return target;
    }
}
